package com.yingma.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yingma.system.entity.JcCarrier;
import com.yingma.system.entity.JcSysOrganization;
import com.yingma.system.dao.JcSysOrganizationDao;
import com.yingma.system.service.JcSysOrganizationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (JcSysOrganization)表服务实现类
 *
 * @author makejava
 * @since 2020-03-18 16:48:29
 */
@Service("jcSysOrganizationService")
public class JcSysOrganizationServiceImpl implements JcSysOrganizationService {
    @Resource
    private JcSysOrganizationDao jcSysOrganizationDao;

    /**
     * 根据组织机构Id查询组织机构的信息
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JcSysOrganization selectById(String id) {
        return jcSysOrganizationDao.selectById(id);
    }

    /**
     * 查询组织机构表中的所有信息
     * @return
     */
    @Override
    public List<JcSysOrganization> queryName() {

        QueryWrapper<JcSysOrganization> queryWrapper=new QueryWrapper<>();
        List<JcSysOrganization> list=jcSysOrganizationDao.selectList(queryWrapper);
        return list;
    }

    /**
     * 根据code查询组织机构
     * @param code
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public List<JcSysOrganization> queryByCondition(String code, Integer pageNum, Integer pageSize) {
        List<JcSysOrganization> list=null;
        QueryWrapper<JcSysOrganization> queryWrapper=new QueryWrapper<JcSysOrganization>();
        if(!code.equals("")&& code!=""){
            queryWrapper.like("NAME",code);
        }

        Page<JcSysOrganization> page=new Page<>(pageNum,pageSize,true);
        IPage<JcSysOrganization> iPages=jcSysOrganizationDao.selectPage(page,queryWrapper);
        list=iPages.getRecords();

        if(list.size()>0){
            list.get(0).setTotalpageNum(new Long(iPages.getPages()).intValue());
            list.get(0).setTotalSize(new Long(iPages.getTotal()).intValue());
        }
        return list;
    }

}
